package com.csyf.manager.controller.system;

import com.csyf.manager.entity.SysTradeType;
import com.csyf.manager.service.SysTradeTypeBiz;
import com.csyf.manager.utils.ResultEntity;
import com.csyf.manager.utils.ResultUtli;
import com.csyf.manager.utils.page.JqGridVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @Author: casper
 * @Description: 代理商费率
 * @Date: Created in 2019/3/13 15:04
 */
@Controller
@RequestMapping("/tradeType")
public class SysTradeTypeController {

    @Autowired
    private SysTradeTypeBiz sysTradeTypeBiz;

    /**
     * 代理商费率列表
     * @param vo
     * @param page
     * @param rows
     * @return
     */
    @PostMapping(value = "list")
    @ResponseBody
    public JqGridVo list(SysTradeType vo, Integer page, Integer rows) {
        return sysTradeTypeBiz.queryTradeTypeList(vo, page, rows);
    }

    /**
     * 编辑代理商费率详情
     * @param model
     * @param mchId
     * @param tradeType
     * @return
     */
    @GetMapping("edit")
    public String editTradeType(Model model, String mchId, String tradeType) {
        SysTradeType sysTradeType = sysTradeTypeBiz.queryTradeTypeByCondition(mchId, tradeType);
        model.addAttribute("tradeType", sysTradeType);
        return "tradeType/tradeTypeDetail";
    }

    /**
     * 编辑代理商费率
     * @param tradeTypeForm
     * @return
     */
    @PostMapping("/edit")
    @ResponseBody
    public ResultEntity editTradeType(SysTradeType tradeTypeForm) {
        int num = sysTradeTypeBiz.updateByTradeType(tradeTypeForm);
        if (num > 0) {
            return ResultUtli.DEFAULT_SUCCESS("编辑费率成功", null);
        } else {
            return ResultUtli.DEFAULT_ERROR("编辑费率失败");
        }
    }

}
